class Solution(object):
    def isIdealPermutation(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        for i, num in enumerate(nums):
            if not i - 1 <= num <= i + 1:
                return False
        return True


data = Solution()
nums = [1, 0, 2]
print(data.isIdealPermutation(nums))
